package com.hawk.eye.server.convert;

import com.hawk.eye.api.storage.dto.ServiceLogReqDTO;
import com.hawk.eye.server.domain.dto.resp.ServiceLogDTO;
import com.hawk.eye.api.storage.dto.ServiceLogRespDTO;
import com.hawk.eye.server.domain.po.AlarmDetailLog;
import com.hawk.eye.server.domain.vo.req.ServiceLogReqVO;
import com.hawk.eye.server.domain.vo.resp.ServiceLogRespVO;
import org.mapstruct.DecoratedWith;
import org.mapstruct.Mapper;
import org.mapstruct.Named;
import org.mapstruct.factory.Mappers;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @author zd
 */
@Mapper
@DecoratedWith(ServiceLogConvert.ServiceLogConvertDecorator.class)
public interface ServiceLogConvert {

    ServiceLogConvert INSTANCE = Mappers.getMapper(ServiceLogConvert.class);

    ServiceLogReqDTO to(ServiceLogReqVO reqVO);

    ServiceLogRespDTO to(ServiceLogDTO logDTO);


    ServiceLogRespVO to(ServiceLogRespDTO reqVO);

    @Named(value = "poToRespDto")
    ServiceLogRespDTO to(AlarmDetailLog alarmDetailLog);

    public abstract class ServiceLogConvertDecorator implements ServiceLogConvert {
        @Override
        public ServiceLogRespDTO to(ServiceLogDTO logDTO) {
            if (logDTO == null) {
                return null;
            }
            ServiceLogRespDTO serviceLogRespDTO = new ServiceLogRespDTO();
            serviceLogRespDTO.setChargeUserId(logDTO.getChargeUserId());
            serviceLogRespDTO.setServiceId(logDTO.getServiceId());
            serviceLogRespDTO.setBaseAlarmId(logDTO.getBaseAlarmId());
            serviceLogRespDTO.setTraceId(logDTO.getTraceId());
            serviceLogRespDTO.setServiceZnName(logDTO.getServiceZnName());
            serviceLogRespDTO.setServiceCnName(logDTO.getServiceCnName());
            serviceLogRespDTO.setChargeUserName(logDTO.getChargeUserName());
            serviceLogRespDTO.setRequestUri(logDTO.getRequestUri());
            serviceLogRespDTO.setAlarmTime(logDTO.getAlarmTime());
            serviceLogRespDTO.setErrorFileName(logDTO.getErrorFileName());
            serviceLogRespDTO.setStackHash(logDTO.getStackHash());
            serviceLogRespDTO.setIsCreateProblem(logDTO.getIsCreateProblem());
            serviceLogRespDTO.setLogMessage(logDTO.getLogMessage());
            return serviceLogRespDTO;
        }
    }

}
